﻿using movie.tool.module.film.model;
using movie.tool.module.http;
using System.Windows;
using System.Windows.Controls;
using System.Net.Http;
using System.Net.Http.Json;

namespace movie.tool.module.film.ui
{
    /// <summary>
    /// MovieInfoPage.xaml 的交互逻辑
    /// </summary>
    public partial class MovieInfoPage : Page
    {
        public MovieParam MovieParam { get; private set; }

        public MovieInfoPage()
        {
            InitializeComponent();
            MovieParam = new MovieParam();
        }

        private void CancelClick(object sender, RoutedEventArgs e)
        {
            ShowMovieListPage();
        }

        private void ShowMovieListPage()
        {
            MainWindow.ShowPage("/module/film/ui/MovieListPage.xaml");
        }

        private async void SubmitClick(object sender, RoutedEventArgs e)
        {
            HttpContent content = JsonContent.Create(MovieParam);
            bool success = await HttpInvoker.PostAsync("movieserver/movies", content);
            if (success)
            {
                ShowMovieListPage();
            }
        }

        private void MovieInfoControl_MovieTagsChanged(string[] obj)
        {
            MovieParam.Tag = obj;
        }

        private void MovieInfoControl_NotifyMovieTagProperty()
        {
            MovieParam.NotifyTagsChanged();
        }
    }
}
